package com.example.smart_home.service;

import com.example.smart_home.mapper.AdminMapper;
import com.example.smart_home.pojo.Admin;
import com.example.smart_home.pojo.AdminExample;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class AdminServiceImpl implements AdminService {
    @Autowired
    AdminMapper adminMapper;
    @Override
    public Admin login(Admin admin) {
        //select * from admin where name='admin' and password='admin'
        //查询条件不是主键，用example来生成查询条件
        AdminExample adminExample = new AdminExample();
        AdminExample.Criteria criteria = adminExample.or();
        criteria.andNameEqualTo(admin.getName());
        criteria.andPasswordEqualTo(admin.getPassword());
        List<Admin> list = adminMapper.selectByExample(adminExample);
        Admin dbAdmin = null;
        //判断集合中有没有数据
        if (list.size() >= 1) {
            dbAdmin = list.get(0);
        }
        return dbAdmin;
    }
}
